/**
 * 
 */
package com.neal.domain.shopping;

import java.io.Serializable;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * @author Neal
 * @version 1.0
 * @description
 */
public class Cart implements Serializable {

	/**
	 * 
	 */
	private static final long serialVersionUID = 6964121478152668212L;

	private Map<String, CartItem> cartItems = new HashMap<String, CartItem>();

	private String address;

	public List<CartItem> getItems() {
		return new ArrayList<CartItem>(cartItems.values());
	}

	public void addItem(Product product) {
		CartItem item = cartItems.get(product.getCode());
		if (item == null) {
			cartItems.put(product.getCode(), new CartItem(product, 1));
		} else {
			item.increaseQuant();
		}
	}

	public double getTotalPrice() {
		double total = 0;
		for (CartItem cartItem : cartItems.values()) {
			total += cartItem.getTotalPrice();
		}
		return total;
	}

	public String getAddress() {
		return address;
	}

	public void setAddress(String address) {
		this.address = address;
	}

}
